package com.gt.quality.apim.service.impl;

import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gt.quality.apim.domain.ApiParamInfo;
import com.gt.quality.apim.service.ApiParamInfoService;
import com.gt.quality.config.SpringBeanUtil;
import com.gt.quality.system.mapper.ApiParamInfoMapper;
import com.gt.quality.base.pojo.BaseLimitRequest;
import com.gt.quality.system.service.GTBaseService;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.support.TransactionTemplate;

import java.util.List;

/**
 * API参数数据集表(ApiParamInfo)表服务实现类
 *
 * @author makejava
 * @since 2026-11-20 09:51:37
 */
@Service("apiParamInfoService")
public class ApiParamInfoServiceImpl extends ServiceImpl<ApiParamInfoMapper, ApiParamInfo> implements GTBaseService<ApiParamInfo>, ApiParamInfoService {


    private ApiParamInfoMapper apiParamInfoMapper;


    /**
     * 往上传递 SqlSessionFactory
     * @return SqlSessionFactory
     */
    @Override
    public SqlSessionFactory getSqlSessionFactory() {
        return super.getSqlSessionFactory();
    }

    /**
     * 往上传递 Mapper
     * @return Mapper
     */
    @Override
    public Class<?> getThisMapperClass() {
        return ApiParamInfoMapper.class;
    }

    /**
     * 往上传递 Transaction
     * @return Transaction
     */
    @Override
    public TransactionTemplate getSpringTx() {
        return SpringBeanUtil.getBean(TransactionTemplate.class);
    }

    @Autowired
    public void setApiParamInfoMapper(ApiParamInfoMapper apiParamInfoMapper) {
        this.apiParamInfoMapper = apiParamInfoMapper;
    }

    /**
     * Description:  分页查询
     *
     * @param limitRequest 分页查询参数
     * @author: makeJava
     * @date: com.sjhy.plugin.tool.TimeUtils@65a47fee
     * @return:com.baomidou.mybatisplus.core.metadata.IPage
     */
    @Override
    public IPage<ApiParamInfo> queryLimitPage(BaseLimitRequest<ApiParamInfo> limitRequest) {
        ApiParamInfo requestBody = limitRequest.getRequestBody();
        IPage<ApiParamInfo> page = getByPageParam(limitRequest);
        if (requestBody==null){
            return apiParamInfoMapper.selectPage(page,new QueryWrapper<>());
        }
        com.alibaba.fastjson2.JSONObject thisObj = JSONObject.from(requestBody);
        QueryWrapper<ApiParamInfo> queryWrapper = queryWrapperBuilder(thisObj,limitRequest);		
        return apiParamInfoMapper.selectPage(page, queryWrapper);
    }

      /**
     * Description:  批量新增优化版
     *
     * @param entityList entityList
     * @author: makeJava
     * @date: com.sjhy.plugin.tool.TimeUtils@65a47fee
     */
    @Override
    public Integer saveBatchByEasyBaseMapper(List<ApiParamInfo> entityList) {

        return apiParamInfoMapper.insertBatch(entityList);
    }

}


